package com.chenchen.tiguan.venue.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.chenchen.tiguan.venue.domain.Venue;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chenchen.tiguan.common.annotation.Log;
import com.chenchen.tiguan.common.core.controller.BaseController;
import com.chenchen.tiguan.common.core.domain.AjaxResult;
import com.chenchen.tiguan.common.enums.BusinessType;
import com.chenchen.tiguan.venue.domain.VenueCourt;
import com.chenchen.tiguan.venue.service.IVenueCourtService;
import com.chenchen.tiguan.common.utils.poi.ExcelUtil;
import com.chenchen.tiguan.common.core.page.TableDataInfo;

/**
 * 场馆下属场地及属性Controller
 * 
 * @author chenchen
 * @date 2025-04-14
 */
@RestController
@RequestMapping("/venue/court")
public class VenueCourtController extends BaseController
{
    @Autowired
    private IVenueCourtService venueCourtService;

    /**
     * 查询场馆下属场地及属性列表
     */
    @PreAuthorize("@ss.hasPermi('venue:court:list')")
    @GetMapping("/list")
    public TableDataInfo list(VenueCourt venueCourt,@Param("venueName") String venueName)
    {
        Venue venue = new Venue();
        venue.setVenueName(venueName);
        venueCourt.setVenue(venue);
        startPage();
        List<VenueCourt> venueCourts = venueCourtService.selectVenueRestCapacity();

        // 遍历 venueCourts 列表
        for (VenueCourt court : venueCourts) {
            System.out.println("修改前------------------");
            System.out.println(court.getRestCapacity());
            venueCourtService.updateVenueCourtRestCapcity(court);
            System.out.println("修改后------------------");
            System.out.println(court.getRestCapacity());
        }
        List<VenueCourt> list = venueCourtService.selectVenueCourtList(venueCourt);
        return getDataTable(list);
    }

    /**
     * 导出场馆下属场地及属性列表
     */
    @PreAuthorize("@ss.hasPermi('venue:court:export')")
    @Log(title = "场馆下属场地及属性", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VenueCourt venueCourt)
    {
        List<VenueCourt> list = venueCourtService.selectVenueCourtList(venueCourt);
        ExcelUtil<VenueCourt> util = new ExcelUtil<VenueCourt>(VenueCourt.class);
        util.exportExcel(response, list, "场馆下属场地及属性数据");
    }

    /**
     * 获取场馆下属场地及属性详细信息
     */
    @PreAuthorize("@ss.hasPermi('venue:court:query')")
    @GetMapping(value = "/{courtId}")
    public AjaxResult getInfo(@PathVariable("courtId") Long courtId)
    {
        return success(venueCourtService.selectVenueCourtByCourtId(courtId));
    }

    /**
     * 新增场馆下属场地及属性
     */
    @PreAuthorize("@ss.hasPermi('venue:court:add')")
    @Log(title = "场馆下属场地及属性", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VenueCourt venueCourt)
    {
        return toAjax(venueCourtService.insertVenueCourt(venueCourt));
    }

    /**
     * 修改场馆下属场地及属性
     */
    @PreAuthorize("@ss.hasPermi('venue:court:edit')")
    @Log(title = "场馆下属场地及属性", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VenueCourt venueCourt)
    {
        return toAjax(venueCourtService.updateVenueCourt(venueCourt));
    }

    /**
     * 删除场馆下属场地及属性
     */
    @PreAuthorize("@ss.hasPermi('venue:court:remove')")
    @Log(title = "场馆下属场地及属性", businessType = BusinessType.DELETE)
	@DeleteMapping("/{courtIds}")
    public AjaxResult remove(@PathVariable Long[] courtIds)
    {
        return toAjax(venueCourtService.deleteVenueCourtByCourtIds(courtIds));
    }

}
